//
//  LKFeedBacklistViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/6/28.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKFeedBacklistViewController.h"
#import "LKFeedBackListCell.h"
#import "LKFeedBackViewController.h"
@interface LKFeedBacklistViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)LKBaseTableview *tableView;
@property(nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation LKFeedBacklistViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"反馈列表";
    [self getMyFeedBacklistData];
    [self createTableview];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadFeedBackList) name:@"reloadFeedBackNotice" object:nil];
    // Do any additional setup after loading the view.
}
-(void)reloadFeedBackList{
    [self.tableView.mj_header beginRefreshing];
}
-(void)createTableview{
    WS(weakSelf)
    self.tableView = [LKBaseTableview setTableviewWithFrame:CGRectZero style:UITableViewStyleGrouped registercellClasss:@[@"LKFeedBackListCell"]];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.emptyDataSetSource = self;
    _tableView.emptyDataSetDelegate = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = viewDefualtColor;
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerReloadData)];
    [self.view addSubview:_tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.view).offset(NAVIGATION_BAR_HEIGHT );
        make.bottom.equalTo(self.view).offset(-65);
    }];

    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
    }
        _tableView.estimatedRowHeight = 500;
        LKBaseButton *submmitBtn = [LKBaseButton buttonWithFrame:CGRectZero type:UIButtonTypeCustom title:@" 期待您的意见反馈" titleColor:[UIColor whiteColor] layercorne:25 font:[UIFont fontWithName:@"PingFangSC-Medium" size:18] backgroudColor:yellowDefaultColor AndActionBlock:^(UIButton * _Nonnull btn) {
            LKFeedBackViewController *vc = [[LKFeedBackViewController alloc] init];
            vc.isListIn = YES;
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }];
    [submmitBtn setImage:[UIImage imageNamed:@"ic_feedback_first_submit"] forState:UIControlStateNormal];
        [self.view addSubview:submmitBtn];
        [submmitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view.mas_bottom).offset(-10);
            make.left.equalTo(self.view).offset(10);
            make.height.mas_equalTo(50);
            make.centerX.equalTo(self.view);
        }];
}
-(void)headerReloadData{
    [self getMyFeedBacklistData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKFeedBackListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKFeedBackListCell"];
    cell.model = self.dataArray[indexPath.section];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return UITableViewAutomaticDimension;

}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc] init];
    return header;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1.0f;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] init];
    return footerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0000000001f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}

-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}
/// 获取我的返回数据列表
-(void)getMyFeedBacklistData{
    NSMutableDictionary *param = [[NSMutableDictionary alloc] initWithDictionary:@{}];
    NSString *sign = [NSString encoingWithDic:param];
    [param setObject:sign forKey:@"sign"];
    [SVProgressHUD showWithStatus:@"加载中..."];
    [SVProgressHUD setDefaultMaskType:SVProgressHUDMaskTypeClear];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:MyFeedbackListUrl header:[LKUserInforTool account].token parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD dismiss];
        [self.tableView.mj_header endRefreshing];
        [self.dataArray removeAllObjects];
        if ([responseObject[@"code"] isEqualToString:@"success"]) {
            NSArray *dataArray = responseObject[@"data"];
            for (NSDictionary *dic in dataArray) {
                LKFeedBackListModel *model = [LKFeedBackListModel modelWithDictionary:dic];
                [self.dataArray addObject:model];
            }
            [self.tableView reloadData];
        }else{
            [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
        }

    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
